#pragma once
#include "base/config.h"

#include <string>
namespace net_tools::base{
class Logendl;
class Logstream{
 public:
  enum Log_level{
    TRACE,
    DEBUG,
    INFO,
    WARN,
    ERROR,
    FATAL,
  };
  Logstream(unsigned int tid);
  ~Logstream();
  Logstream& Init(const char* file,int len,Log_level level);
  void Append(const char* address,short int len);
  void Is_out_buffer(short int len);

  template<typename T>
  void Format_integer(T);

  Logstream& operator<<(Logendl*);

  Logstream& operator<<(bool);
  Logstream& operator<<(short);
  Logstream& operator<<(unsigned short);
  Logstream& operator<<(int);
  Logstream& operator<<(unsigned int);
  Logstream& operator<<(long);
  Logstream& operator<<(unsigned long);
  Logstream& operator<<(long long);
  Logstream& operator<<(unsigned long long);
  Logstream& operator<<(const void*);
  Logstream& operator<<(float);
  Logstream& operator<<(double);
  Logstream& operator<<(char);
  Logstream& operator<<(const char*);
  Logstream& operator<<(const unsigned char*);
  Logstream& operator<<(const std::string&);
  Logstream& operator<<(const timeval&);

 private:
  //     |        |
  //01_12-01:02:01.012132 pid Level FILE LINE
  char        date[5];
  char        time_[10];
  char        utime_[6];
  char        tid_[7];
  char        log_level_[6];
  char        data_buffer[_C::SET_LOG_ONE_LOG_MAX_SIZE + 1];
  short int   base_len_;
  short int   buffer_len_;
  bool        is_out_buffer_;
  char*       file_;
  int         len_;
  __time_t    last_time_;
  short int   min_;
  short int   sec_;
  const char* LogLevelName[6] =
  {
  "TRACE ",
  "DEBUG ",
  "INFO  ",
  "WARN  ",
  "ERROR ",
  "FATAL ",
  };
};

} // namespace net_tools::base